package com.example.fengsam.aidong.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.fengsam.aidong.R;
import com.example.fengsam.aidong.adapter.MoodAdapter;
import com.example.fengsam.aidong.bean.MoodInfo;
import com.jaeger.library.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MoodActivity extends BaseActivity {


    @BindView(R.id.mood_toolbar)
    Toolbar mood_toolbar;
    @BindView(R.id.mood_collapsing_toolbar)
    CollapsingToolbarLayout collapsingToolbar;
    @BindView(R.id.mood_appBar)
    AppBarLayout appBar;
    @BindView(R.id.rv_mood_list)
    RecyclerView rvMoodList;
    @BindView(R.id.top_image)
    ImageView topImage;
//    @BindView(R.id.fb_pichead)
//    FloatingActionButton fbPichead;

    MoodAdapter moodAdapter;
    List<MoodInfo> moodInfos = new ArrayList<>();


//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        initSwipeBackFinish();
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_mood);
//        ButterKnife.bind(this);
//        initView();
//        initData();
//        initAdapter();
//        initListener();
//    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        setContentView(R.layout.activity_mood);
        ButterKnife.bind(this);
        initView();
        initData();
        initAdapter();
        initListener();
    }


    public void initView() {

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            //设置状态栏的颜色
//            this.getWindow().setStatusBarColor(getResources().getColor(R.color.theme_blue));
//        }
//        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
//            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
//            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
//                    localLayoutParams.flags);
//        }

        StatusBarUtil.setTransparent(this);

        rvMoodList.setHasFixedSize(true);
        rvMoodList.setLayoutManager(new LinearLayoutManager(this));

        setSupportActionBar(mood_toolbar);
        ActionBar actionBar = getSupportActionBar();

        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.mipmap.arrow_back_white);
            actionBar.setTitle("朋友圈");
        }
//        collapsingToolbar.setCollapsedTitleGravity(Gravity.CENTER);
//        collapsingToolbar.setExpandedTitleGravity(Gravity.CENTER);////设置展开后标题的位置
//        collapsingToolbar.setTitle("123");
        collapsingToolbar.setExpandedTitleColor(getResources().getColor(R.color.gray));
//        collapsingToolbar.setCollapsedTitleTextColor(getResources().getColor(R.color.black));

    }

    //toolbar返回按钮监听
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case android.R.id.home:
                finish();
        }
        return super.onOptionsItemSelected(item);
    }



    public void initData() {
        for (int i = 0; i < 20; i++) {
            MoodInfo si = new MoodInfo(String.valueOf(i));
            moodInfos.add(si);
        }
    }

    public void initAdapter() {
        moodAdapter = new MoodAdapter(R.layout.mood_item, moodInfos);
        rvMoodList.setAdapter(moodAdapter);
    }

    public void initListener()
    {
        moodAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivity(new Intent(MoodActivity.this,MoodDetailActivity.class));
            }
        });
    }

}
